package com.six.backend.service.impl;

import com.six.backend.config.QiNiuCloudProperties;
import com.six.backend.dao.SummaryDao;
import com.six.backend.pojo.Conference;
import com.six.backend.pojo.Summary;
import com.six.backend.service.SummaryService;
import com.six.backend.utils.QiNiuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author 张重阳
 * @Date 2021-11-09 13:52
 * @Version 1.0
 */
@Service
public class SummaryServiceImpl implements SummaryService {
    @Autowired
    private SummaryDao summaryDao;

    @Autowired
    private QiNiuCloudProperties qiNiuCloudProperties;

    @Override
    /**
     * 获取会议纪要
     * @param map {id 所属会议编号，summaryName 纪要名称}
     * @return List
     */
    public List getSummary(Map map) {
       return summaryDao.getSummary(map);
    }

    @Override
    public Integer deleteSummary(Summary summary) {
        return summaryDao.deleteSummary(summary);
    }

    @Override
    public List<Conference> getConference(String account) {
       return summaryDao.getConference(account);
    }

    @Override
    public void saveSummary(Summary summary) {
        summary.setCreateDate(new Date());
        summary.setAlterDate(new Date());
        summaryDao.saveSummary(summary);
    }

    @Override
    public Boolean deleteSummary(Integer summaryId) {
        String materialId = summaryDao.selectSummaryMaterialId(summaryId);
        return summaryDao.deleteSummary(summaryId) == 1 &&
                summaryDao.deleteSummaryMaterial(materialId) == 1 &&
                QiNiuUtils.delete(qiNiuCloudProperties,materialId).equals("true");
    }


}
